<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('任务执行日志列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>任务名称：</label>
                                <input type="text" name="taskName"/>
                            </li>
                            <li class="select-time">
                                <label>开始时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginStartTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endStartTime]"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status">
                                    <option value="">所有</option>
                                    <option value="1">等待执行</option>
                                    <option value="2">正在执行</option>
                                    <option value="3">执行成功</option>
                                    <option value="4">执行失败</option>
                                    <option value="5">强行停止</option>

                                </select>
                            </li>

                            <li>
                                <label>任务类型：</label>
                                <select name="taskType">
                                    <option value="">所有</option>
                                    <option value="1">trans</option>
                                    <option value="2">job</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="kettle:executeLog:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="kettle:executeLog:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('kettle:executeLog:edit')}]];
        var removeFlag = [[${@permission.hasPermi('kettle:executeLog:remove')}]];
        var prefix = ctx + "kettle/executeLog";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/detail/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                stopUrl: prefix + "/stop/{id}",
                modalName: "任务执行日志",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id', 
                    title: '日志id',
                    visible: false
                },
                {
                    field: 'taskName', 
                    title: '任务名称'
                },

                {
                    field: 'taskType',
                    title: '任务类型',
                    formatter: function (value, row, index) {
                        if(row.taskType == 1){
                            return "trans";
                        }else {
                            return "job";
                        }
                    }
                },
                {
                    field: 'startTime', 
                    title: '开始时间'
                },
                {
                    field: 'endTime', 
                    title: '结束时间'
                },
                {
                    field: 'executionMethod', 
                    title: '执行方式'
                },
                {
                    field: 'status', 
                    title: '状态',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },

                {
                    field: 'taskGroup', 
                    title: '任务组',
                    visible: false

                },

                {
                    field: 'remark', 
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.detailTask(\'' + row.id + '\')"><i class="fa fa-edit"></i>明细</a> ');
                       // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>' );
                        var status = row.status;

                        if( 1 == status || 2 == status){
                            actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.stopTask(\'' + row.id + '\')"><i class="fa-warning"></i>停止</a>');
                        }

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function statusTools(row) {
            var flag = row.status;

            /**
             * 1 : 待执行
             2 : 执行中

             3 : 执行成功
             4 : 执行失败
             5 : 强制停止

             */
            if(flag == 1) {
                return '<i class="fa fa-clock-o" title="等待执行"></i>';
            } else if(flag == 2) {
                return '<i class="fa fa-spin fa-cog " style="color: green"  title="执行中"></i>';
            } else if(flag == 4) {
                return '<i class="fa fa-remove" aria-hidden="true" style="color: red"  title="执行失败" ></i>';
            } else if(flag == 5) {

                return '<i class="fa fa-warning" style="color: red" title="用户手动关闭"></i>';
            }else  if(flag == 3){
                return '<i class="fa  fa-check-circle" style="color: green" title="执行成功"></i>';
            }
        }
    </script>
</body>
</html>